<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>${alert}
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header clearfix">
			<h2 class="pull-left">3차 카테고리 관리 - <small style="color:#ff0000;">${secondInfo.secondCategoryText}</small></h2>
			<div class="pull-right" style="padding-top: 30px">
				<a href="#" id="opensearch" class="btn btn-info">3차카테고리 등록 펼치기/접기</a>
			</div>
		</div>
		
		<div id="searchdiv">
			<div class="clearfix">
				<div class="table-responsive">
					<form id="insertThirdCategory" class="form-horizontal" role="form" method="post" action="thirdCategory.do">
						<table class="table table-bordered">
							<thead>
								<tr class="success">
									<th class="text-center col-md-3">2차카테고리</th>
									<th class="text-center col-md-4">이름</th>
									<th class="text-center col-md-1">정렬순서</th>
									<th class="text-center col-md-2">전시여부</th>
									<th class="text-center col-md-2">추가</th>
								</tr>
							</thead>
							<tbody>
								<tr class="text-center">
									<td class="col-md-3">
										<input type="hidden" name="insertIdSecondCategory" value="${secondInfo.idSecondCategory}"/>
										${secondInfo.secondCategoryText}
									</td>
									<td class="col-md-4"><input type="text" class="form-control" name="insertThirdCategoryText"/></td>
									<td class="col-md-1"><input type="number" class="form-control" name="insertSortKey"/></td>
									<td class="col-md-2">
										<label class="radio-inline"><input type="radio" name="insertIsDisplay" value="1"> Y</label>
										<label class="radio-inline"><input type="radio" name="insertIsDisplay" value="0"> N</label>
									</td>
									<td class="col-md-2"><button type="submit" class="btn btn-primary btn-block btn-sm">등록</button></td>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
				<hr/>
			</div>
		</div>

		<div class="table-responsive">
			<span class="pull-left" style="margin-bottom:10px;">등록 : ${page.totalArticleCount}건 / 활성 : ${display}건 / 비활성 : ${unDisplay}</span>
			<table class="table table-striped table-hover">
				<thead>
					<tr class="warning row">
						<th class="text-center col-md-1">항번</th>
						<th class="text-center col-md-3">2차카테고리</th>
						<th class="text-center col-md-3">이름</th>
						<th class="text-center col-md-1">정렬순서</th>
						<th class="text-center col-md-2">전시여부</th>
						<th class="text-center col-md-1">등록일시</th>
						<th class="text-center col-md-1">수정</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${third}" var="list">
						<form id="updateThirdCategory${list.idThirdCategory}" role="form" method="get" action="thirdCategory.do"></form>
						<input type="hidden" name="idSecond" value="${secondInfo.idSecondCategory}" form="updateThirdCategory${list.idThirdCategory}"/>
						<input type="hidden" name="page" value="${page.nowPage}" form="updateThirdCategory${list.idThirdCategory}"/>
						<input type="hidden" name="param" value="${list.idThirdCategory}" form="updateThirdCategory${list.idThirdCategory}"/>
						<tr class="text-center row">
							<td class="col-md-1">${list.idThirdCategory}</td>
							<td class="col-md-2">
								<select name="updateIdSecondCategory${list.idThirdCategory}" class="form-control" form="updateThirdCategory${list.idThirdCategory}">
									<option>- 선택하세요 -</option>
									<c:forEach items="${second}" var="slist">
										<c:choose>
											<c:when test="${slist.idSecondCategory == list.idSecondCategory}">
												<option value="${slist.idSecondCategory}" selected>${slist.secondCategoryText}</option>
											</c:when>
											<c:otherwise>
												<option value="${slist.idSecondCategory}">${slist.secondCategoryText}</option>
											</c:otherwise>
										</c:choose>
									</c:forEach>
								</select>
							</td>
							<td class="col-md-3">
								<input type="text" class="form-control" name="updateThirdCategoryText${list.idThirdCategory}"
									value="${list.thirdCategoryText}" form="updateThirdCategory${list.idThirdCategory}"/>
							</td>
							<td class="col-md-1">
								<input type="number" class="form-control" name="updateSortKey${list.idThirdCategory}" value="${list.sortKey}" form="updateThirdCategory${list.idThirdCategory}"/>
							</td>
							<td class="col-md-2">
								<c:choose>
									<c:when test="${list.isDisplay == 1}">
										<label class="radio-inline">
											<input type="radio" name="updateIsDisplay${list.idThirdCategory}" value="1" checked form="updateThirdCategory${list.idThirdCategory}"> Y
										</label>
										<label class="radio-inline">
											<input type="radio" name="updateIsDisplay${list.idThirdCategory}" value="0" form="updateThirdCategory${list.idThirdCategory}"> N
										</label>
									</c:when>
									<c:otherwise>
										<label class="radio-inline">
											<input type="radio" name="updateIsDisplay${list.idThirdCategory}" value="1" form="updateThirdCategory${list.idThirdCategory}"> Y
										</label>
										<label class="radio-inline">
											<input type="radio" name="updateIsDisplay${list.idThirdCategory}" value="0" checked form="updateThirdCategory${list.idThirdCategory}"> N
										</label>
									</c:otherwise>
								</c:choose>
							</td>
							<td class="col-md-1">${fn:substring(list.create_date, 0, 4)}-${fn:substring(list.create_date, 4, 6)}-${fn:substring(list.create_date, 6, 8)}</td>
							<td class="col-md-1"><button type="submit" class="btn btn-defalut btn-block btn-sm" form="updateThirdCategory${list.idThirdCategory}">수정</button></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			
		</div>
		
		<div class="text-center">
			<ul class="pagination">

				<!-- 이전 그룹 -->
				<c:choose>
					<c:when test="${page.startPage > page.pageArticleCount}">
						<li><a href="thirdCategory.do?idSecond=${secondInfo.idSecondCategory}&page=${page.startPage-1}">&laquo;</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="#">&laquo;</a></li>
					</c:otherwise>
				</c:choose>
				
				<!-- 페이지 번호 -->
				<c:forEach begin="${page.startPage}" end="${page.endPage}" step="1" var="now">
					<c:choose>
						<c:when test="${page.nowPage == now}">
							<li class="active"><a href="#">${now}</a></li>
						</c:when>
						<c:otherwise>
							<li><a href="thirdCategory.do?idSecond=${secondInfo.idSecondCategory}&page=${now}">${now}</a></li>
						</c:otherwise>
					</c:choose>
				</c:forEach>

				<!-- 다음 그룹 -->
				<c:choose>
					<c:when test="${page.endPage < page.lastGroupFirstPage}">
						<li><a href="thirdCategory.do?idSecond=${secondInfo.idSecondCategory}&page=${page.endPage+1}">&raquo;</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="#">&raquo;</a></li>
					</c:otherwise>
				</c:choose>

			</ul>
		</div>

	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="assets/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#insertThirdCategory").submit(function() {
				
				if (!$("input[name='insertThirdCategoryText']").val().isValue()) {
					alert("카테고리 이름을 입력하세요.");
					$("input[name='insertThirdCategoryText']").focus();
					return false;
				}
				
				if (!$("input[name='insertSortKey']").val().isValue()) {
					alert("정렬순서를 입력하세요.");
					$("input[name='insertSortKey']").focus();
					return false;
				}
				
				if (!$("input[name='insertSortKey']").val().isNumber()) {
					alert("정렬순서는 숫자로만 입력이 가능합니다.");
					$("input[name='insertSortKey']").focus();
					return false;
				}
				
				if (!$("input[name='insertIsDisplay']").is(":checked")) {
					alert("전시여부를 선택해 주세요");
					$("input[name='insertIsDisplay']").focus();
					return false;
				}
				
				if (!confirm("정말 등록하시겠습니까?")) {
					return false;
				}
			});
			
			<c:forEach items="${third}" var="list">
				$("#updateThirdCategory${list.idThirdCategory}").submit(function() {
					
					if ($("select[name='updateIdSecondCategory${list.idThirdCategory}'] > option:selected").index() < 1) {
						alert("2차 카테고리를 선택하세요.");
						$("select[name='updateIdSecondCategory${list.idThirdCategory}']").focus();
						return false;
					}
					
					if (!$("input[name='updateThirdCategoryText${list.idThirdCategory}']").val().isValue()) {
						alert("카테고리 이름을 입력하세요.");
						$("input[name='updateThirdCategoryText${list.idThirdCategory}']").focus();
						return false;
					}
					
					if (!$("input[name='updateSortKey${list.idThirdCategory}']").val().isValue()) {
						alert("정렬순서를 입력하세요.");
						$("input[name='updateSortKey${list.idThirdCategory}']").focus();
						return false;
					}
					
					if (!$("input[name='updateSortKey${list.idThirdCategory}']").val().isNumber()) {
						alert("정렬순서는 숫자로만 입력이 가능합니다.");
						$("input[name='updateSortKey${list.idThirdCategory}']").focus();
						return false;
					}
					
					if (!$("input[name='updateIsDisplay${list.idThirdCategory}']").is(":checked")) {
						alert("전시여부를 선택해 주세요");
						$("input[name='updateIsDisplay${list.idThirdCategory}']").focus();
						return false;
					}
					
					if (!confirm("정말 수정하시겠습니까?")) {
						return false;
					}
					
				});
			</c:forEach>
		});
	</script>
	<script>
		$(function() {
			$("#searchdiv").hide();
			
			$("#opensearch").click(function() {
				$("#searchdiv").toggle();
				return false;
			});
		});
	</script>
  </body>
</html>